'''
Created on Feb 4, 2016

@author: JimmyMo
'''
RAW_INPUT = "raw_input"

class searchresult:
    def __init__(self, hits, took):
        self.hits = hits
        self.took = took
        self.length = len(self.hits)
    
    def get_hit_count(self):
        return len(self.hits)
    
    def get_search_took_time(self):
        return self.took
    
    
class hit:
    def __init__(self, index, doc_type, id, score, title, content, original_from=''):
        self.index = index
        self.doc_type = doc_type
        self.score = score
        self.id = id
        self.title = title
        self.content = content
        self.original_from = original_from
        
    def brief(self):
        if len(self.content) > 120:
            return self.content[0:120] + "..."
        else:
            return self.content
        
    def url(self):
        if self.original_from == RAW_INPUT:
            return "/detail?id=" + self.id
        else: #match url
            if not self.original_from.startswith("http://"):
                return "http://" + self.original_from
            else:
                return self.original_from
        pass
    
    def __str__(self):
        return "title : %s, content: %s" % (self.title, self.content)

def fake_searchresults():
    ar = [hit(elem, elem) for elem in range(1,20)]
    return ar
    